package com.atguigu.democustomer.controller;

import com.atguigu.democustomer.bean.Customer;
import com.atguigu.democustomer.service.CustomerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

//@Controller
@RestController
public class CustomerController {

    @Autowired
    CustomerService customerService;

    //无参请求
    @RequestMapping(value = "test")
//    @ResponseBody
    public String getTest(){
        System.out.println("11111");
        return "success";
    }

    //接受请求路径上的参数
    @RequestMapping("CustomerId/{id}")
    public String getCustomerById(@PathVariable("id") String value){

        System.out.println("1.Controller");

        return customerService.getCustomerById(value);
    }

    //接受请求自身携带的参数
    @RequestMapping("CustomerNameWithAge")
    public String getCustomerByNameAndAge(@RequestParam("name") String na, @RequestParam("age") String ag){
        return "Customer:" + na + ":" + ag;
    }

    //接受请求体中的参数
//    @RequestMapping(value = "saveCustomer",method = RequestMethod.POST)
    @PostMapping("saveCustomer")
    public String saveCustomer(@RequestBody Customer customer){
//        System.out.println(customer);
//        customerService.saveOrUpdate(customer);
        customerService.saveCustomerService(customer);
        return "success";
    }
}
